<template>
	<view
		class="diy-navbar"
		:style="{background:itemData?.style?.background}">
		<uni-grid :column="itemData?.style?.rowsNum || 4" :highlight="false" :showBorder="false">
			<uni-grid-item v-for="(item, index) in itemData.data" :index="index" :key="index" @click="gotoDetail(item)">
				<view class="diy-navbar-item main-flex">
					<image class="diy-navbar-item-icon" :src="item.imgUrl" mode="aspectFill"></image>
					<text class="diy-navbar-item-text text_line1" :style="{color:item.color}">{{item.text}}</text>
				</view>
			</uni-grid-item>
		</uni-grid>
	</view>
</template>

<script>
	import { getNode } from '@/utils/ty.js'
	export default {
		data() {
			return {
				//单个宽度
				item_width: '25%'
			}
		},
		props: ['itemData'],
		created() {
			this.item_width = 100 / Math.abs(this.itemData.style.rowsNum) + '%';
		},
		methods: {
			/*跳转页面*/
			async gotoDetail(e) {
				if (e.name === '/pages/index/index?type=1') {
					// #ifdef MP-WEIXIN
					const height = uni.getWindowInfo().windowHeight
					// #endif
					// #ifndef MP-WEIXIN
					const height = uni.getSystemInfoSync().windowHeight
					// #endif
					const query = uni.createSelectorQuery()
					// const headerNode = await getNode(query, '#header')
					const indexGoodsnode = await getNode(query, '#indexGoods')
					uni.pageScrollTo({
						scrollTop: indexGoodsnode?.top
					})
				} else {
					this.gotoPage(e?.name)
				}
			}
		}
	}
</script>

<style>
	.diy-navbar {
		margin-bottom: 20rpx;
		padding: 20rpx 0;
		border-radius: 6rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
	}
	.diy-navbar-item {
		height: 100%;
		flex-direction: column;
		justify-content: center;
	}
	.diy-navbar-item-icon {
		width: 70rpx;
		height: 70rpx;
	}
	.diy-navbar-item-text {
		width: 100%;
		line-height: 66rpx;
		font-size: 26rpx;
		text-align: center;
	}
	.diy-navbar .item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;
		width: 120rpx;
		height: 140rpx;
	}

	.diy-navbar .item image {
		width: 70rpx;
		height: 70rpx;
	}

	.diy-navbar-text {
		display: block;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 100%;
		overflow: hidden;
		line-height: 66rpx;
		font-size: 26rpx;
		text-align: center;
	}
</style>
